COMMIT_MESSAGE = "Bump podspec to"

lane :dependencies do
  cocoapods(podfile: "Example/")
  carthage(command: "update")
end

lane :tests do
  scan(workspace: "Example/SugarRecord.xcworkspace", scheme: "SugarRecord_Tests", device: "iPhone 6", skip_build: true)
end

lane :carthage_project do
  carthage(command: "build", no_skip_current: true, verbose: true)
end

lane :travis do
  dependencies
  carthage_project
  tests
  danger
end
  
lane :push do
  podspec = "SugarRecord.podspec"
  last_version = version_get_podspec(path: podspec)
  version = version_bump_podspec(path: podspec)
  git_commit(path: [podspec, "./Example/Podfile.lock"], message: "#{COMMIT_MESSAGE} #{version}")
  changelog = changelog_from_git_commits
  changelog ||= "No changelog"
  github_release = set_github_release(
    repository_name: "carambalabs/SugarRecord",
    api_token: ENV['GITHUB_TOKEN'],
    name: version,
    tag_name: version,
    description: changelog,
    commitish: "master"
  )
  sh("git fetch --tags")
  push_to_git_remote(remote_branch: 'master', force: false, tags: true)
  pod_push(allow_warnings: true, verbose: true)
end